const formContainer = {
  type: 'form',
  rules: {
    bussType: [
      {
        required: true,
        message: '业务类型不能为空'
      }
    ],
    projectName: [
      {
        required: true,
        message: '请输入项目名称'
      }
    ],
    channelCode: [
      {
        required: true,
        message: '请输入渠道码'
      }
    ],
    supplier: [
      {
        required: true,
        message: '请输入合作方名称'
      }
    ],
    status: [
      {
        required: true,
        message: '请选择是否启用'
      }
    ]
  },
  columnCount: 2,
  body: [
    {
      type: 'select',
      name: 'bussType',
      label: '业务类型',
      placeholder: '请选择业务类型',
      fieldNames: { label: 'dictLabel', value: 'dictValue' },
      api: '/system/dict/data/type/t_buss_type'
    },
    {
      type: 'input-text',
      name: 'projectName',
      label: '项目名称',
      placeholder: '请输入项目名称'
    },
    {
      type: 'input-text',
      name: 'channelCode',
      label: '渠道码',
      placeholder: '请输入渠道码'
    },
    {
      type: 'input-text',
      name: 'supplier',
      label: '合作方名称',
      placeholder: '请输入合作方名称'
    },
    {
      type: 'select',
      name: 'status',
      label: '是否启用',
      placeholder: '请选择是否启用',
      fieldNames: { label: 'dictLabel', value: 'dictValue' },
      api: '/system/dict/data/type/sys_normal_disable'
    }
  ]
}

const columns = [
  {
    field: 'origin',
    title: '数据源',
    comType: 'lowCode',
    body: {
      type: 'mapping',
      value: '${origin}',
      cache: true,
      api: {
        url: '/system/dict/data/type/t_origin_data',
        responseAdaptor: (response) => {
          const data = response.data
          const map = {}
          data.forEach((item) => {
            map[item.dictValue] = item.dictLabel
          })
          return {
            data: map
          }
        }
      }
    }
  },
  {
    field: 'originType',
    title: '映射类型'
  },
  {
    field: 'dataOrigin',
    title: '映射数据源',
    comType: 'lowCode',
    body: {
      type: 'mapping',
      value: '${dataOrigin}',
      cache: true,
      api: {
        url: '/system/dict/data/type/t_origin_data_map',
        responseAdaptor: (response) => {
          const data = response.data
          const map = {}
          data.forEach((item) => {
            map[item.dictValue] = item.dictLabel
          })
          return {
            data: map
          }
        }
      }
    }
  },
  {
    field: 'mapCapSeq',
    title: '映射数据值'
  },
  {
    field: 'mapName',
    title: '映射数据名称'
  },
  {
    field: 'mapCode',
    title: '映射数据编码'
  },
  {
    field: 'status',
    title: '是否启用',
    comType: 'lowCode',
    body: {
      type: 'mapping',
      value: '${status}',
      cache: true,
      api: {
        url: '/system/dict/data/type/sys_normal_disable',
        responseAdaptor: (response) => {
          console.log('response', response)
          const data = response.data
          const map = {}
          data.forEach((item) => {
            map[item.dictValue] = item.dictLabel
          })
          return {
            data: map
          }
        }
      }
    }
  },
  {
    field: 'operation',
    title: '操作',
    comType: 'lowCode',
    body: {
      type: 'space',
      body: [
        {
          type: 'link',
          actionType: 'dialog',
          reflectAttr: { type: 'primary' },
          body: '修改',
          dialog: {
            title: '修改',
            body: {
              ...formContainer,
              data: {
                bussType: '${bussType}',
                projectName: '${projectName}',
                channelCode: '${channelCode}',
                supplier: '${supplier}',
                status: '${status}'
              },
              api: {
                url: '/supplier/info/updateSupplierInfo',
                method: 'post',
                successMsg: '修改成功',
                data: {
                  bussType: '${bussType}',
                  projectName: '${projectName}',
                  channelCode: '${channelCode}',
                  supplier: '${supplier}',
                  status: '${status}',
                  id: '${id}'
                }
              }
            }
          }
        }
      ]
    }
  }
]

const querys = [
  {
    prop: 'origin',
    label: '数据源',
    type: 'select',
    placeholder: '请选择业务类型',
    fieldNames: { label: 'dictLabel', value: 'dictValue' },
    api: '/system/dict/data/type/t_origin_data'
  },
  {
    prop: 'dataOrigin',
    label: '映射数据源',
    type: 'select',
    placeholder: '请选择业务类型',
    fieldNames: { label: 'dictLabel', value: 'dictValue' },
    api: '/system/dict/data/type/t_origin_data_map'
  },
  {
    prop: 'originType',
    label: '映射类型',
    placeholder: '请选择映射类型',
    type: 'select',
    fieldNames: { label: 'dictLabel', value: 'dictValue' },
    visibleOn: '${dataOrigin} === "YKB"',
    api: '/system/dict/data/type/t_origin_type_YKB'
  },
  {
    prop: 'originType',
    label: '映射类型',
    placeholder: '请选择映射类型',
    type: 'select',
    fieldNames: { label: 'dictLabel', value: 'dictValue' },
    visibleOn: '${dataOrigin} === "JD"',
    api: '/system/dict/data/type/t_origin_type_JD'
  },
  {
    prop: 'value',
    label: '源数据值',
    placeholder: '请输入源数据值',
    type: 'input-text'
  },
  {
    type: 'select',
    prop: 'status',
    label: '是否启用',
    placeholder: '请选择是否启用',
    fieldNames: { label: 'dictLabel', value: 'dictValue' },
    api: '/system/dict/data/type/sys_normal_disable'
  }
]

export default {
  type: 'page',
  body: {
    type: 'crud',
    columns,
    querys,
    api: {
      url: '/dict/origin/selecDictOriginMapList',
      responseData: ''
    },
    tableTop: {
      type: 'el-row',
      reflectAttr: {
        type: 'flex',
        justify: 'end',
        align: 'center'
      },
      body: {
        type: 'button',
        body: '新增',
        actionType: 'dialog',
        reflectAttr: { type: 'primary' },
        dialog: {
          title: '新增',
          body: {
            ...formContainer,
            api: {
              url: '/supplier/info/insertSupplierInfo',
              method: 'post',
              data: {
                bussType: '${bussType}',
                projectName: '${projectName}',
                channelCode: '${channelCode}',
                supplier: '${supplier}',
                status: '${status}'
              }
            }
          }
        }
      }
    }
  }
}
